package com.zft.oss;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class DemoController {
	
	@RequestMapping(value="request1.do", method = { RequestMethod.GET ,RequestMethod.POST})
	@ResponseBody
	public Map<String, Object> test(@RequestBody String data ,HttpServletResponse response) throws IOException{
		Map<String, Object> map = new HashMap<String, Object>();
		
		response.addHeader( "Access-Control-Allow-Origin", "*" ); 
		response.addHeader( "Access-Control-Allow-Methods", "POST" ); 
		response.addHeader( "Access-Control-Max-Age", "1000" );
		
		System.out.println("jieshou:"+data);
		BackResult br = new BackResult();
		br.setResult(0);
		map.put("Name", "SEND_ALARM_ACK");
		map.put("Data", br);
		return map;
		
	}
	
//	@CrossOrigin(origins="*" ,methods={RequestMethod.POST},maxAge=1000)
	@RequestMapping(value="request2.do",/* produces="text/plain;charset=UTF-8",*/method = { RequestMethod.GET ,RequestMethod.POST})
	@ResponseBody
	public Map<String, Object> test2(@RequestBody String data,HttpServletResponse response/*,HttpServletRequest request*/) throws IOException{
		Map<String, Object> map = new HashMap<String, Object>();
		response.addHeader( "Access-Control-Allow-Methods", "POST" ); 
		response.addHeader( "Access-Control-Max-Age", "1000" );
		response.addHeader( "Access-Control-Allow-Origin", "*" ); 
		/*
		StringBuilder sb1 = new StringBuilder();
		BufferedReader reader = request.getReader();
		String line;
		while((line = reader.readLine())!=null){
			sb1.append(line).append('\n');
		}
		reader.close();
		String sb = sb1.toString();
		System.out.println("data:"+sb);*/
		
		System.out.println("jieshou2:"+data);
		BackResult br = new BackResult();
		br.setResult(0);
		map.put("Name", "SEND_DATACREATE_ACK");
		map.put("Data", br);
		return map;
		
	}
	
	@RequestMapping(value="request3.do", method = { RequestMethod.GET ,RequestMethod.POST})
	@ResponseBody
	public Map<String, Object> test3(@RequestBody String data ,HttpServletResponse response) throws IOException{
		Map<String, Object> map = new HashMap<String, Object>();
		
		response.addHeader( "Access-Control-Allow-Origin", "*" ); 
		response.addHeader( "Access-Control-Allow-Methods", "POST" ); 
		response.addHeader( "Access-Control-Max-Age", "1000" );
		
		System.out.println("jieshou,haha:"+data);
		BackResult br = new BackResult();
		br.setResult(0);
		map.put("Name", "SEND_DATACREATE_ACK");
		map.put("Data", br);
		return map;
		
	}

}
